{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0b776d43",
   "metadata": {},
   "source": [
    "* week10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "194e53fa",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid character '：' (U+FF1A) (178008782.py, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [1]\u001b[1;36m\u001b[0m\n\u001b[1;33m    准备工作：\u001b[0m\n\u001b[1;37m        ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid character '：' (U+FF1A)\n"
     ]
    }
   ],
   "source": [
    "准备工作：\n",
    "product_list = [\n",
    "    [\"自行车，299\"],\n",
    "    [\"iphone 14 pro\",800],\n",
    "    [\"NFT 盲盒\",28]\n",
    "    [\"徐老师的Python书\",\"80\"]\n",
    "]\n",
    "shopping_car = []\n",
    "1.Alipay = input(\"请输入余额：\")\n",
    "  print()\n",
    "// # 情景1： 用户输入了商品编号： shopping\n",
    "2.    user_choice = input(\"请输入商品编号：\")\n",
    "      # 0,1,2,3\n",
    "3.    if 钱够，Alipay - 商品的价格\n",
    "       shopping_car.append(product_list[user_choice])\n",
    "        else print(\"您的余额已不足，请更换支付方式~\")\n",
    "4. # 情景2： 用户输入\"q\",退出购买\n",
    "  print(shopping_car)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "df231db5",
   "metadata": {},
   "outputs": [],
   "source": [
    "准备工作："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9aaf9078",
   "metadata": {},
   "outputs": [],
   "source": [
    "product_list = ["
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f23cb341",
   "metadata": {},
   "outputs": [],
   "source": [
    "    [\"自行车，299\"],"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "40eaca75",
   "metadata": {},
   "outputs": [],
   "source": [
    "    [\"iphone 14 pro\",800],"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b7fb5717",
   "metadata": {},
   "outputs": [],
   "source": [
    "    [\"NFT 盲盒\",28]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "442468dc",
   "metadata": {},
   "outputs": [],
   "source": [
    "    [\"徐老师的Python书\",\"80\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8fb85c9a",
   "metadata": {},
   "outputs": [],
   "source": [
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3eeff327",
   "metadata": {},
   "outputs": [],
   "source": [
    "shopping_car = []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3c23c400",
   "metadata": {},
   "outputs": [],
   "source": [
    "1.Alipay = input(\"请输入余额：\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "66120344",
   "metadata": {},
   "outputs": [],
   "source": [
    "  print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e3b749e5",
   "metadata": {},
   "outputs": [],
   "source": [
    "// # 情景1： 用户输入了商品编号： shopping"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "89d80588",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b2067118",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "867bb265",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Input you salary please:6000\n",
      "0 ('iphone7', 6000)\n",
      "1 ('book', 150)\n",
      "2 ('bike', 1000)\n",
      "3 ('bag', 300)\n",
      "你要买什么？>>>:book\n",
      "invaliad option\n",
      "0 ('iphone7', 6000)\n",
      "1 ('book', 150)\n",
      "2 ('bike', 1000)\n",
      "3 ('bag', 300)\n",
      "你要买什么？>>>:book\n",
      "invaliad option\n",
      "0 ('iphone7', 6000)\n",
      "1 ('book', 150)\n",
      "2 ('bike', 1000)\n",
      "3 ('bag', 300)\n",
      "你要买什么？>>>:2\n",
      "买了 ('bike', 1000) ，还剩下 5000元\n",
      "0 ('iphone7', 6000)\n",
      "1 ('book', 150)\n",
      "2 ('bike', 1000)\n",
      "3 ('bag', 300)\n"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "Interrupted by user",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "Input \u001b[1;32mIn [2]\u001b[0m, in \u001b[0;36m<cell line: 9>\u001b[1;34m()\u001b[0m\n\u001b[0;32m     12\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m index,item \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28menumerate\u001b[39m(product_list):\n\u001b[0;32m     13\u001b[0m     \u001b[38;5;28mprint\u001b[39m(index,item)\n\u001b[1;32m---> 14\u001b[0m user_choise \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43minput\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m你要买什么？>>>:\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m     15\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m user_choise\u001b[38;5;241m.\u001b[39misdigit():\n\u001b[0;32m     16\u001b[0m     user_choise \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mint\u001b[39m(user_choise)\n",
      "File \u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\ipykernel\\kernelbase.py:1075\u001b[0m, in \u001b[0;36mKernel.raw_input\u001b[1;34m(self, prompt)\u001b[0m\n\u001b[0;32m   1071\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_allow_stdin:\n\u001b[0;32m   1072\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m StdinNotImplementedError(\n\u001b[0;32m   1073\u001b[0m         \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mraw_input was called, but this frontend does not support input requests.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m   1074\u001b[0m     )\n\u001b[1;32m-> 1075\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_input_request\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m   1076\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mprompt\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1077\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_parent_ident\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mshell\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1078\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_parent\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mshell\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1079\u001b[0m \u001b[43m    \u001b[49m\u001b[43mpassword\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[0;32m   1080\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\ipykernel\\kernelbase.py:1120\u001b[0m, in \u001b[0;36mKernel._input_request\u001b[1;34m(self, prompt, ident, parent, password)\u001b[0m\n\u001b[0;32m   1117\u001b[0m             \u001b[38;5;28;01mbreak\u001b[39;00m\n\u001b[0;32m   1118\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyboardInterrupt\u001b[39;00m:\n\u001b[0;32m   1119\u001b[0m     \u001b[38;5;66;03m# re-raise KeyboardInterrupt, to truncate traceback\u001b[39;00m\n\u001b[1;32m-> 1120\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyboardInterrupt\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInterrupted by user\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;28mNone\u001b[39m\n\u001b[0;32m   1121\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m:\n\u001b[0;32m   1122\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlog\u001b[38;5;241m.\u001b[39mwarning(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInvalid Message:\u001b[39m\u001b[38;5;124m\"\u001b[39m, exc_info\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m: Interrupted by user"
     ]
    }
   ],
   "source": [
    "product_list = [\n",
    "    ('iphone7',6000),\n",
    "    ('book',150),\n",
    "    ('bike', 1000),\n",
    "    ('bag', 300),\n",
    "]\n",
    "shopping_list = []\n",
    "salary = input(\"Input you salary please:\")\n",
    "if salary.isdigit():\n",
    "    salary = int(salary)\n",
    "    while True:\n",
    "        for index,item in enumerate(product_list):\n",
    "            print(index,item)\n",
    "        user_choise = input(\"你要买什么？>>>:\")\n",
    "        if user_choise.isdigit():\n",
    "            user_choise = int(user_choise)\n",
    "            if user_choise < len(product_list) and user_choise >=0:\n",
    "                p_item = product_list[user_choise]\n",
    "                if p_item[1] <= salary:\n",
    "                    shopping_list.append(p_item)\n",
    "                    salary -= p_item[1]\n",
    "                    print(\"买了 %s ，还剩下 %s元\" % (p_item,salary))\n",
    "                else:\n",
    "                    print(\"你的余额剩下 %s 元,买个毛线\" %salary )\n",
    "            else:\n",
    "                print(\"你选择的编号 %s 无效\" %user_choise)\n",
    "        elif user_choise == 'q':\n",
    "            print(\"-------shopping list-------\")\n",
    "            for p in shopping_list:\n",
    "                print(p)\n",
    "            exit()\n",
    "        else:\n",
    "            print(\"invaliad option\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "f956dbb3",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (200191886.py, line 27)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [21]\u001b[1;36m\u001b[0m\n\u001b[1;33m    print(\"您的余额还有:\"Alipay)\u001b[0m\n\u001b[1;37m                   ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "product_list = [\n",
    "    [\"自行车，299\"],\n",
    "    [\"iphone 14 pro\",8000],\n",
    "    [\"NFT 盲盒\",28],\n",
    "    [\"徐老师的Python书\",\"80\"]\n",
    "]\n",
    "\n",
    "shopping_car = []\n",
    "Alipay = int(input(\"请输入余额:\"))\n",
    "while True:\n",
    "    print(\"--------商品列表-------\")\n",
    "    for i in range(4):\n",
    "        print(\"商品标号：\"+str(i),product_list[i])\n",
    "    user_chioce = input(\"请输入商品标号:\")\n",
    "    # 情景1：shopping\n",
    "    if user_chioce.isdigit():\n",
    "        # 判断钱够不够，商品是谁？==> product_list[user_chioce][1]\n",
    "        if Alipay >= product_list[int(user_chioce)][1]:\n",
    "            Alipay = Alipay - product_list[int(user_chioce)][1] # 买完商品剩余的钱\n",
    "            shopping_car.append(product_list[int(user_chioce)])\n",
    "            print(\"您购买的商品已增加到购物车~~您的余额还有:\",Alipay)\n",
    "        else:\n",
    "            print(\"您的余额不足，请更换支付方式~~\")\n",
    "    #情景2：用户输入“q”退出\n",
    "    elif user_chioce == \"q\":\n",
    "        print(\"您的购物车:\",shopping_car)\n",
    "        print(\"您的余额还有:\"Alipay)\n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5df909d2",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ef1bdcc4",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
